
import VueRouter from 'vue-router'
import Vue from 'vue'
Vue.use(VueRouter)
import Home from './components/Home'
import About from './components/About'
import News from './components/News'
import NotFound from '@/components/NotFound'
import Login from '@/components/Login'
import Love from './components/Love'
import User from '@/components/Login/User'
import Enterprise from '@/components/Login/Enterprise'

// import { component } from 'vue/types/umd'
const routes=[
    {
        path:'/',
        redirect:'/home'
    },
    {
        
        path:"/home",
        component:Home

    },
    {
        path:"/about",
        component:About

    },
    {
        path:"/news/:id",
        component:News,
        props:true
    },
    {
        path:"/love",
        component:Love,
        // props:true
    },
    {
        path:'/login',
        component:Login,
        children:[
            {
                name:'userLogin',
                path:'/login/user',
                component:User

            },
            {
                name:'enterpriseLogin',
                path:'/login/enterprise',
                component:Enterprise

            }
        ]
    },
    {
        path:"*",
        component:NotFound,


        
    }
]
const router=new VueRouter({
    routes,
    scrollBehavior(to,from){
        if(to.path==='/love'){
            return {x:0,y:0}

        }
        return {x:0,y:0}
    }
})
router.beforeEach(function(to,from,next){
    if(to.path==='/about'){
        alert('禁止访问')
        return next('/login')
    }
    next()
})
router.afterEach((to,from)=>{
    console.log(to)
    console.log(from)
})
export default router
